package com.example.designModel.原型模式.简历;

import java.io.Console;

/**
 * XXXXXXXXX
 *
 * @author brad zhang
 * @version 2.0
 * @date 2021/11/17 17:20
 */
public class Program {

    public static void main(String[] args) throws CloneNotSupportedException {
        Resume a = new Resume("大鸟");
        a.SetPersonalInfo("男", "29");
        a.SetWorkExperience("1998-2000", "XX公司");

        Resume b = (Resume)a.Clone();
        b.SetWorkExperience("1998-2006", "YY企业");

        Resume c = (Resume)a.Clone();
        c.SetWorkExperience("1998-2003", "ZZ企业");

        a.Display();
        b.Display();
        c.Display();
    }
}

//简历
class Resume implements Cloneable {

    private String name;
    private String sex;
    private String age;

    private WorkExperience work;

    public Resume(String name) {
        this.name = name;
        work = new WorkExperience();
    }

    private Resume(WorkExperience work) throws CloneNotSupportedException {
        this.work = (WorkExperience)work.Clone();
    }

    //设置个人信息
    public void SetPersonalInfo(String sex, String age) {
        this.sex = sex;
        this.age = age;
    }

    //设置工作经历
    public void SetWorkExperience(String workDate, String company) {
        work.WorkDateP = workDate;
        work.CompanyP = company;
    }

    //显示
    public void Display() {
        System.out.printf("%s %s %s", name, sex, age);
        System.out.println();
        System.out.printf("工作经历：%s %s", work.WorkDateP, work.CompanyP);
        System.out.println();

    }

    public Object Clone() throws CloneNotSupportedException {
        Resume obj = new Resume(this.work);

        obj.name = this.name;
        obj.sex = this.sex;
        obj.age = this.age;

        return obj;
    }
}

//工作经历
class WorkExperience implements Cloneable {

    private String workDate;
    public String WorkDateP;

    public String getWorkDateP() {
        return workDate;
    }

    public void setWorkDateP(String workDateP) {
        workDate = workDateP;
    }

    private String company;
    public String CompanyP;

    public String getCompanyP() {
        return company;
    }

    public void setCompanyP(String companyP) {
        company = companyP;
    }

    public Object Clone() throws CloneNotSupportedException {
        return (Object)this.clone();
    }
}